<?php /** @noinspection ALL */


namespace app\admin\controller;


use think\facade\Db;


class Task {

	function show($page=1,$pageSize=10){
		$input=input();

		$condition = ' and 1=1';

		if (!empty($input['title'])) {
			$input['title']=trim($input['title']);
			$condition .= " and option_products.title like '%{$input['title']}%' ";
		}

		$list = Db::query("select task.number,option_products.title,FROM_UNIXTIME(task.add_time,'%Y-%m-%d %H:%i:%s')  as add_time,task_type.cycle,task.status,task.income,FROM_UNIXTIME(task.end_time,'%Y-%m-%d %H:%i:%s') as end_time from task join option_products on option_products.id = task.product_id join task_type on task_type.id=task.task_typeid where 1".$condition." order by task.id desc limit ".(($page-1)*$pageSize).",$pageSize");

		$total_num=Db::query("select count(task.id) as sum from task join option_products on option_products.id = task.product_id join task_type on task_type.id=task.task_typeid where 1".$condition);

		return json(['code' => 1, 'data' => $list,'total_num'=>$total_num[0]['sum']]);
	}


}